package com.itheima.movement.controller;

import com.itheima.entity.dto.MovementCommentDto;
import com.itheima.entity.pojo.MovementComment;
import com.itheima.entity.vo.MovementCommentVo;
import com.itheima.entity.vo.Result;
import com.itheima.movement.service.MovementCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author :wujunjie
 * createTime :2022-12-23 14:30
 * description :
 */
@RestController
@RequestMapping("movementService/movementComment")
public class MovementCommentController {
    @Autowired
    private MovementCommentService movementCommentService;

    @PostMapping
    public Result insertComment (@RequestBody MovementCommentDto movementCommentDto){
           Boolean insert=movementCommentService.insertComment(movementCommentDto);
        if (insert){
            return Result.success();
        }
        return Result.error();
    }

    @PutMapping
    public Result deleteComment (@RequestParam String id){
        Boolean deleteComment=movementCommentService.deleteComment(id);
        if (deleteComment){
            return Result.success();
        }
        return Result.error();
    }

    @GetMapping
    public Result selectByMovementIds (@RequestParam String id){
        List<String> ids=new ArrayList<>();
        ids.add(id);
        List<MovementCommentVo> movementComments = movementCommentService.selectByMovementIds(ids);
        return Result.success(movementComments);
    }


}
